import WXRealLogUtil from "../../StartAb/WXRealLogUtil";
import ResManager from "./ResManager";

const { ccclass, property } = cc._decorator;

export default class Coordinates {
    static config = {
    }

    static loadLvCoordinate(level: number, cb: () => void) {
        let key = ResManager.getLevelResNameByIndex(level);
        if (Coordinates.config[key] != null) {
            cb && cb();
            return;
        }
        cc.assetManager.loadBundle("LevelAb", (err: Error, b: cc.AssetManager.Bundle) => {
            if (err) {
                window['wx']?.showToast?.({
                    title: '资源加载失败,麻烦重新进入',
                    icon: 'error',
                    duration: 2000
                })
                WXRealLogUtil.error("加载关卡坐标出错:" + err.message);
                return console.error(err.message);
            }
            b.load("level_coord", cc.JsonAsset, (err: Error, res: cc.JsonAsset) => {
                if (err) {
                    cc.error("%s load res failed:%s", this.name, err.message)
                    WXRealLogUtil.error("加载关卡坐标出错:" + err.message);
                    return
                }
                Coordinates.config = res.json;
                cb && cb();
            })
        })
    }

}